package plataforma.crud.cih;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Groupbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Toolbar;
import org.zkoss.zul.Vlayout;

import plataforma.base.cdp.Criterio;
import plataforma.cih.botoes.BotaoPesquisar;

public abstract class PainelPesquisa extends Vlayout {

	protected List<Criterio> criterios = new ArrayList<Criterio>();

	protected List<Criterio> criteriosAgregacao = new ArrayList<Criterio>();

	protected Groupbox filtro;

	public List<Criterio> getCriterios() {
		return criterios;
	}

	public void setCriterios(List<Criterio> criterios) {
		this.criterios = criterios;
	}

	protected Checkbox checkHabilitarConsulta = new Checkbox();

	protected BotaoPesquisar btPesquisar = new BotaoPesquisar();

	protected GridDados grid = new GridDados();

	public PainelPesquisa() {

		montar();

		definirListener(btPesquisar);
	}

	private void montar() {

		filtro = new Groupbox();
		this.appendChild(filtro);

		org.zkoss.zul.Caption caption = new org.zkoss.zul.Caption();
		filtro.appendChild(caption);
		caption.appendChild(new Label("Filtro da Pesquisa"));
		caption.appendChild(checkHabilitarConsulta);

		filtro.setOpen(false);
		filtro.setClosable(true);
		filtro.addEventListener("onOpen", new EventListener() {

			public void onEvent(Event event) throws Exception {
				checkHabilitarConsulta.setChecked(filtro.isOpen());

			}

		});

		filtro.appendChild(grid);

		btPesquisar.setLabel("Pesquisar");
		Toolbar toolbar = new Toolbar();
		toolbar.setAlign("start");
		toolbar.setWidth("100%");
		filtro.appendChild(toolbar);
		toolbar.appendChild(btPesquisar);
	}
	

	public void definirListener(Button botaoFiltra) {

		botaoFiltra.addEventListener("onClick", new EventoFiltrar());

	}

	public final class EventoFiltrar implements EventListener {

		@SuppressWarnings("unchecked")
		public void onEvent(Event event) throws Exception {

			filtrar();
			
		}
	}

	public abstract void filtrar();



}
